<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
  </head>
  <body>
    <script type="text/javascript">
      const _findMostType = (array) => {
        // 补全代码
        /**
         * 请补全JavaScript代码，要求找到参数数组中出现频次最高的数据类型，并且计算出出现的次数，要求以数组的形式返回。
          注意：
          1. 基本数据类型之外的任何引用数据类型皆为"object"
          2. 当多种数据类型出现频次相同时将结果拼接在返回数组中，出现次数必须在数组的最后
          __findMostType([0,0,'',''])
          ['number','string',2]或['string','number',2]
        */
        if (array && array.length) {
          var countObj = {}
          var itemType = undefined
          array.forEach((item) => {
            itemType = typeof item
            if (itemType === 'object') return
            if (countObj[itemType]) {
              countObj[itemType].count++
            } else {
              countObj[itemType] = {
                count: 1,
                typeStr: itemType
              }
            }
          })
          var countArr = Object.values(countObj)
          countArr = countArr.sort((a, b) => { return b.count - a.count })
          var resArr = countArr.map((item) => { return item.typeStr })
          resArr.push(countArr[0].count)
          return resArr
        } else {
          return []
        }
      }
      // _findMostType([0,0,4,2,'','', ''])
      // console.log(JSON.stringify(_findMostType([1,"1",{},{},2,3,4,3,3,"","","","",""])) === '["number","string",6]')
    </script>
  </body>
</html>
